package com.zhiyi.coco.controller;

import com.alibaba.fastjson.JSON;
import com.zhiyi.coco.entity.Temperature;
import com.zhiyi.coco.service.TemperatureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "TemperatureController", description = "饮品温度相关编辑")
@RestController
@RequestMapping("/temperature")
@Log4j
public class TemperatureController {
    @Autowired
    private TemperatureService service;

    @ApiOperation("获取Material表中的数据")
    @ResponseBody
    @RequestMapping("/getAll/{fId}")
    private List<Temperature> getAll(@PathVariable Integer fId) {
        List<Temperature> list = service.getAll(fId);
        if (list == null) {
            return null;
        }
        return list;
    }

    @ApiOperation("根据商品编号删除temperature表中的数据")
    @ResponseBody
    @RequestMapping("/deleteByfId/{fId}")
    public Boolean deleteByfId(@PathVariable Integer fId) {
        Integer i = service.deleteByfId(fId);
        return true;
    }

    @ApiOperation("根据商品编号删除temperature表中的数据")
    @ResponseBody
    @RequestMapping("/insertSelective")
    public Boolean insertSelective(Temperature temperature) {
        Integer i = service.insertSelective(temperature);
        log.info(JSON.toJSONString(temperature));
        if(i>0){
            return true;
        }
        return false;
    }
}
